package com.kx.yooli.kx.wechat.service.credit.impl;

import com.kx.yooli.kx.wechat.entity.credit.CreditEntity;
import com.kx.yooli.kx.wechat.mapper.credit.ICreditMapper;
import com.kx.yooli.kx.wechat.mapper.user.UserInfoMapper;
import com.kx.yooli.kx.wechat.po.user.UserInfo;
import com.kx.yooli.kx.wechat.service.credit.ICreditService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author john_sqwen-childe.wen
 * date 2024/5/23
 * PROJECT_NAME wechat
 * description create CreditServiceImpl by john_sqwen
 * and  value is
 */
@Service
public class CreditServiceImpl extends ServiceImpl<ICreditMapper,CreditEntity> implements ICreditService {
    private final Logger log = LoggerFactory.getLogger(CreditServiceImpl.class);
    @Resource
    private  ICreditMapper iCreditMapper;
    private final UserInfoMapper userInfoMapper;

    public CreditServiceImpl(UserInfoMapper userInfoMapper) {
        this.userInfoMapper = userInfoMapper;
    }

    @Override
    public List<CreditEntity> selectByIdCard(String mobile) {
        if(StringUtils.isAllBlank(mobile)){
            throw  new RuntimeException("未获取到需要查询的参数!");
        }
        UserInfo userInfo = userInfoMapper.selectCertNoByMobile(mobile);
        String idCard = "";
        if(null != userInfo){
            if(!userInfo.getCertNo().isBlank()) {
                idCard = userInfo.getCertNo();
            }
        }
        if(idCard.isBlank()){
            throw  new RuntimeException("身份证号未能正常的获取 !");
        }
        List<CreditEntity> creditEntities = iCreditMapper.selectByIddCar(idCard);
        log.info("list value is {}", creditEntities.toString());
        return creditEntities;
    }
}
